package com.business.commons.baseUtil;

import java.lang.reflect.ParameterizedType;

public class ClassUtils {

	
	private ClassUtils(){
	}
	
	
	private static ClassUtils instance;
	
	public static ClassUtils get() {
		if(instance == null ){
			instance = new ClassUtils(); 
		}
		return instance;
	}
	
	public  String getTCalss(Class c, String field) throws Exception {
		ParameterizedType pt = (ParameterizedType) c.getField(field)
				.getGenericType();
		int len = (pt.getActualTypeArguments().length);
		if (len >= 1) {
			String classT = (pt.getActualTypeArguments()[0]) + "";
			classT = classT.replace("class", "");
			return classT.trim();
		}
		return null;

		// Class c1 = pt.getActualTypeArguments().getClass();
		// System.out.println(c1);

	}
	
	public  String getTCalss(Class c, String field,int index) throws Exception {
		ParameterizedType pt = (ParameterizedType) c.getField(field)
				.getGenericType();
		int len = (pt.getActualTypeArguments().length);
		if (len >= index) {
			String classT = (pt.getActualTypeArguments()[index]) + "";
			classT = classT.replace("class", "");
			return classT.trim();
		}
		return null;

		// Class c1 = pt.getActualTypeArguments().getClass();
		// System.out.println(c1);

	}
}
